package com.design.model.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: study
 * @className: Composite
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-07-03 11:43
 * @version: v1.0
 **/
public class Composite extends Component {

    private List<Component> children = new ArrayList<>();

    public Composite(String name) {
        super(name);
    }

    @Override
    public void add(Component component) {
        this.children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);

    }

    @Override
    public void display(int depth) {
        System.out.printf("-%d%s\n", depth, name);
        children.forEach(e -> e.display(depth));
    }
}
